/*
 * pid.h
 *
 *  Created on: Dec 10, 2023
 *      Author: 86152
 */
#include "zf_common_headfile.h"

#ifndef PID_H_
#define PID_H_

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MINMAX(input, low, upper) MIN(MAX(input, low), upper)

typedef struct {
    float kp;    //P
    float ki;    //I
    float kd;    //D
    float i_max; //integrator_max
    float p_max; //integrator_max
    float d_max; //integrator_max

    float low_pass;

    float out_p;
    float out_i;
    float out_d;

    float error;
    float pre_error;
    float pre_pre_error;
} pid_param_t;


float pid_solve(pid_param_t *pid, float error);

float pid_pd(pid_param_t *pid, float error);

float increment_pid_solve(pid_param_t *pid, float error);

float increment_pd(pid_param_t *pid, float error);

float bangbang_pid_solve(pid_param_t *pid, float error);

float changable_pid_solve(pid_param_t *pid, float error);

void pid_pd_adjust(pid_param_t *pid, float kp, float kd);

void pid_adjust(pid_param_t *pid, float kp, float ki, float kd, float i_max, float low_pass);


extern pid_param_t suspmotor_pid;


#endif /* PID_H_ */
